/**
* @project admin-go-api
* @name router
* @descriptions 接口路由配置
* @author 寒锋
* @date 2023-12-12 15:21:59
 */

package router

import (
	"admin-go-api/api/controller"
	"admin-go-api/common/config"
	"admin-go-api/middleware"
	"github.com/gin-gonic/gin"
	swaggerFiles "github.com/swaggo/files"
	ginSwagger "github.com/swaggo/gin-swagger"
	"net/http"
)

func InitRouter() *gin.Engine {
	router := gin.New()
	// 跌机恢复
	router.Use(gin.Recovery())
	// 跨域中间件
	router.Use(middleware.CorsMiddleware())
	// 图片访问路径静态文件夹可直接访问
	router.StaticFS(config.Config.ImageSettings.UploadDir, http.Dir(config.Config.ImageSettings.UploadDir))
	// 日志中间件
	router.Use(middleware.LoggerMiddleware())
	register(router)
	return router
}

func register(router *gin.Engine) {
	// todo 后续接口url
	router.GET("/api/captcha", controller.Captcha)
	router.GET("swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
	router.POST("/api/login", controller.Login)
	router.POST("/api/ajax/upload", controller.Upload) // 单图片上传
	api := router.Group("/api", middleware.AuthMiddleware(), middleware.NodeMiddleware(), middleware.SysOperationLogMiddleware())
	{
		// 岗位相关路由
		sysPost := api.Group("/sysPost")
		{
			sysPost.GET("/index", controller.GetSysPostList)
			sysPost.GET("/vo/list", controller.QuerySysPostVoList)
			sysPost.POST("/store", controller.CreateSysPost)
			sysPost.GET("/show", controller.GetSysPostById)
			sysPost.PUT("/update", controller.UpdateSysPost)
			sysPost.PUT("/state", controller.UpdateSysPostStatus)
			sysPost.DELETE("/destroy", controller.DeleteSysPostById)
			sysPost.DELETE("/batch/destroy", controller.BatchDeleteSysPost)
		}
		// 部門相關路由
		sysDept := api.Group("/sysDept")
		{
			sysDept.GET("/index", controller.GetSysDetList)
			sysDept.GET("/vo/list", controller.GetSysDeptVoList)
			sysDept.POST("/store", controller.CreateSysDept)
			sysDept.GET("/show", controller.GetSysDeptById)
			sysDept.PUT("/update", controller.UpdateSysDept)
			sysDept.DELETE("/destroy", controller.DeleteSysDeptById)
		}
		// 菜单接口
		sysMenu := api.Group("/sysMenu")
		{
			sysMenu.GET("/index", controller.GetSysMenuList)
			sysMenu.GET("/vo/list", controller.GetSysMenuVoList)
			sysMenu.POST("/store", controller.CreateSysMenu)
			sysMenu.GET("/show", controller.GetSysMenuById)
			sysMenu.PUT("/update", controller.UpdateSysMenu)
			sysMenu.DELETE("/destroy", controller.DeleteSysMenu)
		}
		// 角色接口
		sysRole := api.Group("/sysRole")
		{
			sysRole.GET("/index", controller.GetSysRoleList)
			sysRole.GET("/vo/list", controller.GetSysRoleVoList)
			sysRole.POST("/store", controller.CreateSysRole)
			sysRole.GET("/show", controller.GetSysRoleById)
			sysRole.PUT("/update", controller.UpdateSysRole)
			sysRole.PUT("/state", controller.UpdateSysRoleState)
			sysRole.DELETE("/destroy", controller.DeleteSysRole)
			sysRole.GET("/getRoleMenuIdByRoleId", controller.GetRoleMenuIdByRoleId)
			sysRole.PUT("/assignPermissions", controller.AssignPermissions)
		}
		// 管理员接口
		sysAdmin := api.Group("/sysAdmin")
		{
			sysAdmin.GET("/index", controller.GetSysAdminList)
			sysAdmin.POST("/store", controller.CreateSysAdmin)
			sysAdmin.GET("/show", controller.GetSysAdminInfoById)
			sysAdmin.PUT("/update", controller.UpdateSysAdmin)
			sysAdmin.PUT("/state", controller.UpdateSysAdminState)
			sysAdmin.DELETE("/destroy", controller.DeleteSysAdmin)
			sysAdmin.PUT("/restPassword", controller.RestSysAdminPassword)
			sysAdmin.PUT("/updatePersonal", controller.UpdatePersonal)
			sysAdmin.PUT("/updatePersonalPassword", controller.UpdatePersonalPassword)
		}
		// 登录日志接口
		sysLoginInfo := api.Group("/sysLoginInfo")
		{
			sysLoginInfo.GET("/index", controller.GetSysLoginInfoList)
			sysLoginInfo.DELETE("/destroy", controller.DeleteSysLoginInfoById)
			sysLoginInfo.DELETE("/batchDestroy", controller.BatchDeleteSysLoginInfo)
			sysLoginInfo.DELETE("/clean", controller.CleanSysLoginInfo)
		}
		// 操作日志接口
		sysOperationLog := api.Group("/sysOperationLog")
		{
			sysOperationLog.GET("/index", controller.GetSysOperationLogList)
			sysOperationLog.DELETE("/destroy", controller.DeleteSysOperationLogById)
			sysOperationLog.DELETE("/batchDestroy", controller.BatchDeleteSysOperationLog)
			sysOperationLog.DELETE("/clean", controller.CleanSysOperationLog)
		}
	}
}
